Skip to content

Conversation

@js07
Copy link
Collaborator

@js07 js07 commented Jun 3, 2025

WHY

Components that take a file as input accept a file path (e.g., /tmp/my-file.csv), a remove URL (e.g. https://example.com/file.txt), or both. For convenience, ideally every component that accepts only a file path would also accept a remote file URL. Those components can be updated to use the helper, added in this PR, to get a readable stream and file metadata by passing either a local file path or remote file URL.

For example:

import { getFileStreamAndMetadata } from "@pipedream/platform";

export default {
  type: "action",
  props: {
    file: {
      type: "string",
      label: "File",
      description: "The URL or local path to the file (e.g. \`/tmp/myFile.csv\`)",
      optional: true,
    },
  },
  async run({ $ }) {
    const { file: filePathOrUrl } = this;
    const { stream, metadata } = await getFileStreamAndMetadata(filePathOrUrl);
    // Do something with the file stream and metadata
  },
};

Summary by CodeRabbit

  • New Features
    • Added the ability to stream files from both local paths and remote URLs, with support for retrieving file metadata such as size, content type, last modified date, name, and ETag.
  • Tests
    • Introduced comprehensive tests to ensure correct file streaming and metadata extraction, as well as proper cleanup of temporary files.
  • Chores
    • Updated the package version to 3.1.0 and added new dependencies for MIME type handling and UUID generation.

js07 added 4 commits June 3, 2025 18:38
This commit introduces a new helper for working with file streams,
providing a unified interface for reading local and remote files.
@vercel
Copy link

vercel bot commented Jun 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2025 6:56pm
pipedream-docs ⬜️ Ignored (Inspect) Jun 4, 2025 6:56pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jun 4, 2025 6:56pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

A new module, file-stream, was introduced to provide asynchronous utilities for streaming files from local paths or remote URLs, along with metadata extraction. Comprehensive tests for this module were added. The main package index now exports these new utilities and extends an interface. The package version was updated to 3.1.0 with added dependencies.

Changes

File(s) Change Summary
platform/lib/file-stream.ts New module implementing getFileStream, getFileStreamAndMetadata, and FileMetadata interface.
platform/tests/file-stream.js Added comprehensive tests for file streaming and metadata extraction (local and remote sources), including error handling and temp file cleanup verification.
platform/lib/index.ts Exported new functions and type from file-stream; extended AxiosRequestConfig interface with optional body property.
platform/package.json Updated package version from 3.0.3 to 3.1.0; added mime-types and uuid dependencies; reordered devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant file-stream
    participant fs
    participant fetch
    participant tmp

    Caller->>file-stream: getFileStreamAndMetadata(pathOrUrl)
    alt pathOrUrl is local file
        file-stream->>fs: stat(pathOrUrl)
        file-stream->>fs: createReadStream(pathOrUrl)
        file-stream-->>Caller: { stream, metadata }
    else pathOrUrl is remote URL
        file-stream->>fetch: fetch(pathOrUrl)
        alt content-length present
            file-stream-->>Caller: { stream, metadata }
        else content-length missing
            file-stream->>tmp: createTempFile()
            file-stream->>fs: write response to temp file
            file-stream->>fs: createReadStream(temp file)
            file-stream-->>Caller: { stream, metadata }
            Note right of file-stream: Temp file cleaned up after stream ends/errors
        end
    end
Loading

Poem

In the warren, files now stream,
Local or remote, they flow like a dream.
With metadata in paw, and cleanup in tow,
Rabbits test, hop, and watch data grow.
Version hops up—three point one oh!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

platform/lib/file-stream.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:170:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65653d8 and edc6b54.

⛔ Files ignored due to path filters (1)
  • platform/dist/file-stream.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • platform/lib/file-stream.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • platform/lib/file-stream.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint Code Base
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@js07 js07 marked this pull request as ready for review June 3, 2025 23:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
platform/__tests__/file-stream.js (1)

33-33: Consider using dynamic port allocation to avoid conflicts.

The hard-coded port 3892 could cause test failures if the port is already in use. Consider using port 0 to let the OS assign an available port.

-  const testPort = 3892;
+  let testPort;

Then update the server listen callback to capture the assigned port:

server.listen(0, () => {
  testPort = server.address().port;
  resolve();
});
platform/lib/file-stream.ts (2)

1-9: Consolidate fs imports for cleaner code.

Multiple imports from the fs module can be consolidated into a single import statement.

-import {
-  createReadStream, promises as fs,
-} from "fs";
-import { createWriteStream } from "fs";
+import {
+  createReadStream, createWriteStream, promises as fs,
+} from "fs";

82-82: Document the non-null assertion for clarity.

The non-null assertion operator ! is used here because we've already checked that the header exists. Consider adding a comment for clarity.

-    ? new Date(headers.get("last-modified")!)
+    ? new Date(headers.get("last-modified")!) // Safe: checked for existence above
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7211d1 and 4d2678d.

⛔ Files ignored due to path filters (6)
  • platform/dist/file-stream.d.ts is excluded by !**/dist/**
  • platform/dist/file-stream.js is excluded by !**/dist/**
  • platform/dist/index.d.ts is excluded by !**/dist/**
  • platform/dist/index.js is excluded by !**/dist/**
  • platform/package-lock.json is excluded by !**/package-lock.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • platform/__tests__/file-stream.js (1 hunks)
  • platform/lib/file-stream.ts (1 hunks)
  • platform/lib/index.ts (3 hunks)
  • platform/package.json (1 hunks)
🔇 Additional comments (5)
platform/package.json (1)

3-3: Version bump is appropriate for new feature addition.

The minor version increment from 3.0.3 to 3.1.0 correctly follows semantic versioning for adding new functionality (file-stream utilities).

platform/lib/index.ts (2)

13-19: File-stream exports are properly structured.

The new exports for getFileStreamAndMetadata, getFileStream, and FileMetadata type are correctly added and follow the existing export pattern.


170-171: ESLint suppressions are reasonable for dynamic types.

The @typescript-eslint/no-explicit-any suppressions for $event and body are acceptable given their dynamic nature in the platform context.

Also applies to: 219-220

platform/__tests__/file-stream.js (1)

1-196: Excellent test coverage for the file-stream module.

The test suite comprehensively covers:

  • Local and remote file streaming
  • Metadata extraction with various HTTP headers
  • Error handling for invalid paths/URLs
  • Temporary file cleanup scenarios
  • Edge cases like missing content-length headers

Great attention to testing resource cleanup!

platform/lib/file-stream.ts (1)

2-2:

✅ Verification successful

Verify Node.js version compatibility for stream/web import.

The stream/web module requires Node.js 16.5.0 or later. Ensure your platform supports this version.


🏁 Script executed:

#!/bin/bash
# Check if package.json specifies Node.js version requirements
fd "package.json" --exec grep -E "engines|node" {} \;

Length of output: 2232


No action needed: Node.js ≥18.0.0 already satisfies stream/web requirement

The project’s package.json enforces "node": ">=18.0.0", which exceeds the 16.5.0 minimum needed for the stream/web import.

Copy link
Collaborator

@jcortes jcortes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding a few suggestions with the help of AI!

js07 and others added 6 commits June 4, 2025 14:22
* Create and use safeStat function
* Check for response.body when fetching file
* Use uuid package to generate temp file name
* Use mime-types package to lookup content type
* Cleanup temp file on error

Co-authored-by: Jorge Cortes <[email protected]>
* use basename to get file name from file url
* lookup content type from file name if no content-type header
@js07
Copy link
Collaborator Author

js07 commented Jun 4, 2025

Thanks for the review @jcortes! All of your suggestions have been applied.

@js07 js07 requested a review from jcortes June 4, 2025 19:09
Copy link
Collaborator

@jcortes jcortes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @js07 looks great to me! Thanks!

@js07 js07 merged commit 21dddb3 into master Jun 4, 2025
8 checks passed
@js07 js07 deleted the platform-file-stream-util branch June 4, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants